package com.zlm.design.iterator;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

/**
 * @author zlm
 * @date 2025/4/18
 */
public class Main {

    public static void main(String[] args) throws IOException {
        /*list<User> userList = new ArrayList<>();


        readUsers((user)->{
            System.out.println(user);
            userList.add(user);
        });*/

        File file = new File("demo.user");
        UserFile userFile = new UserFile(file);
        for (User user : userFile) {
            System.out.println(user);
        }
    }

    private static void readUsers(Consumer<User> userConsumer) throws IOException {
        List<String> lines = Files.readAllLines(new File("demo.user").toPath());
        for (String line : lines) {
            String midString = line.substring(1, line.length() - 1);
            String[] split = midString.split(",");
            User user = new User(split[0], Integer.parseInt(split[1]));
            userConsumer.accept(user);
        }
    }
}
